﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MMOArpgServer.Tool
{
    public static class ServerLogHelper
    {
        private static string _LogPath;
        

        public static void LogOut(string className, int lineNumber, string logContent)
        {
            DateTime logTime = DateTime.Now;
            if (_LogPath != null || _LogPath != "")
            {
                CreateLogFile();
            }
            try {
                string outContent = className + "LineNumber: " + "Content: " + logContent;
                StreamWriter streamWriter = new StreamWriter(_LogPath,true);
                streamWriter.Write(logTime.ToString("hh:mm:ss") + "  " + outContent);
                streamWriter.Close();
            }
            catch (Exception e) {
                Console.WriteLine("日志输出失败: "+e.Message);
            }
        }
        public static void WorringLogOut(string className, int lineNumber, string logContent)
        {

            LogOut(className, lineNumber, "this is a WorringLog: " + logContent);

        }

        public static void ErrorLogOut(string className, int lineNumber, string logContent)
        {
            LogOut(className, lineNumber, "this is a WorringLog: " + logContent);
        }

        private static void CreateLogFile()
        {
            try
            {
                _LogPath = Directory.GetCurrentDirectory() + "\\ServerLog";
                if (!Directory.Exists(_LogPath)) {
                    Directory.CreateDirectory(_LogPath);
                }
                _LogPath += DateTime.Now.ToString("yyyyMMdd")+"txt";
                if (!File.Exists(_LogPath)) {
                    File.Create(_LogPath);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("日志文件生成失败: " + e.Message);

            }
        }
    }
}
